import { ENV_MAP_A } from "@/config";
import { Environment, useHelper } from "@react-three/drei";
import { MutableRefObject, useRef } from "react";
import { Object3D, Object3DEventMap, SpotLight, SpotLightHelper } from "three";

export default function Lights({ debug = true }) {
  const lightRef = useRef<SpotLight>(null);
  useHelper(
    lightRef as MutableRefObject<Object3D<Object3DEventMap>>,
    SpotLightHelper
  );
  return (
    <>
      <Environment files={ENV_MAP_A} />
      <ambientLight intensity={0.5} />
      <spotLight
        position={[0, 6.5, 0]}
        angle={Math.PI / 5} // 聚光角度
        penumbra={0.1} // 边缘的柔和度
        intensity={100} // 光的强度
        distance={6}
        ref={debug ? lightRef : null}
      />
    </>
  );
}
